/**
 * 3
 *  
 * @Author : roryrywang
 * @DateTime : 24-8-25 下午2:39
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> nums(n);

    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }

    vector<int> stack;
    bool flag = true;
    for (int i = n - 1; i >= 0; --i) {
        while (!stack.empty() && nums[i] <= nums[stack[stack.size() - 1]]) {
            stack.pop_back();
        }
        if (nums[i] >= x && !stack.empty()) {
            flag = false;
            break;
        }
        stack.push_back(i);
    }

    if (!flag) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> numsSorted(nums);
    numsSorted.push_back(x);
    sort(numsSorted.begin(), numsSorted.end());

    int res = 0x3f3f3f3f;
    for (int k = 0; k < numsSorted.size(); ++k) {
        int tmp = 0;
        for (int i = 0, j = 0; j <= n; ++i, j++) {
            if (j == k) {
                i--;
                continue;
            }
            if (nums[i] != numsSorted[j]) tmp++;
        }
        res = min(res, tmp);
    }

    cout << res << endl;
    return 0;
}